package sevice

import (
	"errors"
	"gorm.io/gorm"
	"server/global"
	"server/model"
	"server/model/request"
)
// @author: [piexlmax](https://github.com/piexlmax)
// @function: getMenuTreeMap
// @description: 获取当前角色树
// @return: err error, menus []model.SysMenu
func GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []model.SysMenu){
	err = global.GVA_DB.Where("authority_id = ?", info.AuthorityId).Order("sort").Find(&menus).Error
	return err, menus
}

// @author: [piexlmax](https://github.com/piexlmax)
// @function: AddBaseMenu
// @description: 添加基础路由
// @param: menus model.SysBaseMenu
// @return: err error
func AddBaseMenu(menu model.SysBaseMenu)(err error){
	if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
		 err = errors.New("存在重复name, 请修改name")
	}
	err = global.GVA_DB.Create(&menu).Error
	return err
}


